<script>
  $(document).ready(function() {
	$("#dtText3").datepicker(
		{
			onSelect: function(dtText, inst) { 
				if(dtText.length>0){
					eventDate = dtText.split("/");
					newEventDate = eventDate[2]+'-'+eventDate[0]+'-'+eventDate[1];
					var url = "<?php echo $html->url(array('controller'=>'events','plugin'=>'events','action'=>'browse'))?>";		
					url += '/ByTime:'+newEventDate;
					window.location = url;
				}
			}
		}
	);
  });
</script>
<div class="events_filter">
<div class="eventbytime">
<?php

	$browseArray2 = null;
	if ($session->check('eventBrowseParams'))
		$browseArray2 = $session->read('eventBrowseParams');
	//debug($browseArray2);

	echo "<h4>".__("Narrow By Time")."</h4>";
	$currentAppliedMark = "";
	$currentAppliedMark = ($browseArray2['ByTime']=='All')? "&#187; ":"";
	echo $currentAppliedMark . $html->link(__('All', true), array('controller'=>'events','plugin'=>'events','action'=>'browse','ByTime'=>'All'));
	$currentAppliedMark = ($browseArray2['ByTime']=='Today')? "&#187; ":"";
	echo "<br/>" . $currentAppliedMark;
	echo $html->link(__('Today', true), array('controller'=>'events','plugin'=>'events','action'=>'browse','ByTime'=>'Today'));
	$currentAppliedMark = ($browseArray2['ByTime']=='Tomorrow')? "&#187; ":"";
	echo "<br/>" . $currentAppliedMark;
	echo $html->link(__('Tomorrow', true), array('controller'=>'events','plugin'=>'events','action'=>'browse','ByTime'=>'Tomorrow'));
	$currentAppliedMark = ($browseArray2['ByTime']=='This_Weekend')? "&#187; ":"";
	echo "<br/>" . $currentAppliedMark;
	echo $html->link(__('This Weekend', true), array('controller'=>'events','plugin'=>'events','action'=>'browse','ByTime'=>'This_Weekend'));
	$currentAppliedMark = ($browseArray2['ByTime']=='This_Week')? "&#187; ":"";
	echo "<br/>" . $currentAppliedMark;
	echo $html->link(__('This Week', true), array('controller'=>'events','plugin'=>'events','action'=>'browse','ByTime'=>'This_Week'));
	$currentAppliedMark = ($browseArray2['ByTime']=='Next_Week')? "&#187; ":"";
	echo "<br/>" . $currentAppliedMark;
	echo $html->link(__('Next Week', true), array('controller'=>'events','plugin'=>'events','action'=>'browse','ByTime'=>'Next_Week'));
	$currentAppliedMark = ($browseArray2['ByTime']=='Week_After_Next')? "&#187; ":"";
	echo "<br/>" . $currentAppliedMark;
	echo $html->link(__('Week After Next', true), array('controller'=>'events','plugin'=>'events','action'=>'browse','ByTime'=>'Week_After_Next'));
	$currentAppliedMark = ($browseArray2['ByTime']=='Past')? "&#187; ":"";
	echo "<br/>" . $currentAppliedMark;
	echo $html->link(__('Past', true), array('controller'=>'events','plugin'=>'events','action'=>'browse','ByTime'=>'Past'));
	$currentAppliedMark = (substr_count($browseArray2['ByTime'],'-')>0)? "&#187; ":"";
	echo "<br/>" . $currentAppliedMark;
	if (substr_count($browseArray2['ByTime'],'-')>0) {
		$dtboxvalue = $browseArray2['ByTime'];
	} else {
		$dtboxvalue = __('Jump to date');
	}
	echo "<input type='label' value='" . $dtboxvalue . "' readonly='true' name = 'dtText3' id='dtText3'  onClick='$(this).datepicker().datepicker( \"show\" );' size='10' />";
	echo "<br/>";
?>
</div>
<div class="eventsortby">
<?php
	echo "<h4>".__("Sort By")."</h4>";
	$currentAppliedMark = ($browseArray2['SortBy']=='Date')? "&#187; ":"";
	echo $currentAppliedMark . $html->link(__('Date', true), array('controller'=>'events','plugin'=>'events','action'=>'browse','SortBy'=>'Date'));
	$currentAppliedMark = ($browseArray2['SortBy']=='Most_Popular')? "&#187; ":"";
	echo "<br/>" . $currentAppliedMark;
	echo $html->link(__('Most Popular', true), array('controller'=>'events','plugin'=>'events','action'=>'browse','SortBy'=>'Most_Popular'));
	$currentAppliedMark = ($browseArray2['SortBy']=='Recently_Added')? "&#187; ":"";
	echo "<br/>" . $currentAppliedMark;
	echo $html->link(__('Recently Added', true), array('controller'=>'events','plugin'=>'events','action'=>'browse','SortBy'=>'Recently_Added'));
	$currentAppliedMark = ($browseArray2['SortBy']=='Free')? "&#187; ":"";
	echo "<br/>" . $currentAppliedMark;
	echo $html->link(__('Free', true), array('controller'=>'events','plugin'=>'events','action'=>'browse','SortBy'=>'Free'));
	echo "<br/>";
	echo "<br/>";
?>
</div>
<div class="catcheckbox_group">
<?php
	$categoryTree = cri("Events.EventCategory")->getOptions();
	$CatOptions = array();
	/*
	$CatOptions[] = array(
		'name' => 'All Categories',
		'value' => 'A',
		//'onClick' => 'if(this.checked)alert("Selected:"+this.value);else alert("deselected:"+this.value);'
		'onClick' => 'return showEventFilters(this);'
	);
	*/
	$ischeck = 'true';
	$tmpCatList = $browseArray2['ByCategory'];
	if(is_array($tmpCatList)) {
		$tmpCatList = array_flip($tmpCatList);
	}
	foreach($categoryTree as $CatValue => $CatLabel) {
		if(!is_array($tmpCatList)) {
			$ischeck = 'false';
		} else {
			$ischeck = (array_key_exists($CatValue,$tmpCatList))?'true':'false';
		}
		$CatOptions[] = array(
			'name' => $CatLabel,
			'value' => $CatValue,
			'checked' => $ischeck,
			'onClick' => 'return showEventFilters(this);'
		);
	}
	echo "<h4>".__("Show By Category")."</h4>";
	
	//$tmpCatList = $browseArray2['ByCategory'];
	$currentAppliedMark = (!is_array($tmpCatList))? "&#187; ":"";
	echo $currentAppliedMark . $html->link(__('All Categories', true), array('controller'=>'events','plugin'=>'events','action'=>'browse','ByCategory'=>'A'));
	echo $form->input('event_category_id',array('label'=>'','type'=>'select','multiple'=>'checkbox','options'=>$CatOptions));
	
?>
</div>
</div>
<script type="text/javascript">

function showEventFilters(caller)
{
	tmpCC = caller.value;
	tmpSS = (caller.checked)?"1":"0";
	//alert(tmpCC + " = " + tmpSS);
	var url = "<?php echo $html->url(array('controller'=>'events','plugin'=>'events','action'=>'browse'))?>";	
	url += '/ByCategory:'+tmpCC+'/ischecked:'+tmpSS;
	//alert(url);
	window.location = url;
	return true;
}

</script>